<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('我发起的流程')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <div class="row">
                        <ul>
                            <li>
                                <label>流程名称：</label>
                                <input type="text" name="processDefinitionName"/>
                            </li>
                            <li>
                                <label>单号：</label>
                                <input type="text" name="businessKey"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
        </div>

    </div>
</div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
     <script th:inline="javascript">
         var detailFlag = [[${@permission.hasPermi('system:flow:myStartProcessDetail')}]];
         var processInstanceStatusDatas = [[${@dict.getType('process_instance_status')}]];
         var activeProcessInstanceFlag = [[${@permission.hasPermi('system:flow:activeProcessInstance')}]];
         var suspendProcessInstanceFlag = [[${@permission.hasPermi('system:flow:suspendProcessInstance')}]];
         var prefixFlow = ctx + "flow";
         $(function() {
             var options = {
                 url: prefixFlow + "/getMyHistoricProcessInstance",
                 activeProcessInstanceUrl: prefixFlow+"/activeProcessInstance",
                 suspendProcessInstanceUrl: prefixFlow+"/suspendProcessInstance",
                 modalName: "我发起的流程",
                 striped: true,      //是否显示行间隔色
                 showToggle: false,
                 loadingFontSize:20,
                 showRefresh: false,                   // 是否显示刷新按钮
                 showColumns: false,                   // 是否显示隐藏某列下拉框
                 showToggle: false,
                 showSearch: false,                     // 是否显示检索信息
                 columns: [
                     {
                         title: '序号',
                         formatter: function (value, row, index) {
                             return index+1;
                         }
                     },
                     {
                         field: 'processDefinitionName',
                         title: '流程名称'
                     },

                     {
                         field: 'businessKey',
                         title: '单号',
                         formatter: function(value, row, index) {
                             var fromDetailUrl= row.fromDetailUrl;

                             return '<a class="success" href="javascript:void(0)" onclick="fromDetailUrl(\'' + fromDetailUrl+ '\')">'+value+'</a>'
                         }
                     },
                     {
                         field: 'startUserName',
                         title: '流程发起人'
                     },
                     {
                         field: 'isFinished',
                         title: '流程状态',
                         formatter: function(value, row, index) {
                             return $.table.selectDictLabel(processInstanceStatusDatas, value);
                         }
                     },
                     {
                         field: 'processSpendTime',
                         title: '流程用时'
                     },
                     {
                         field: 'startTime',
                         title: '流程创建时间'
                     },
                     {
                         field: 'endTime',
                         title: '流程结束时间'
                     },

                     {
                         title: '操作',
                         align: 'center',
                         formatter: function(value, row, index) {
                             var actions = [];
                             var isFinished= row.isFinished;
                             var processInstanceStatus= row.processInstanceStatus;
                             if(processInstanceStatus==1&&isFinished==0){
                                 actions.push('<a class="btn btn-danger btn-xs ' + suspendProcessInstanceFlag + '" href="javascript:void(0)" onclick="$.operate.suspendProcessInstance(\'' + row.id + '\')"><i class="fa fa-eye"></i>挂起</a> ');
                             }
                             if(processInstanceStatus==2&&isFinished==0){
                                 actions.push('<a class="btn btn-success btn-xs ' + activeProcessInstanceFlag + '" href="javascript:void(0)" onclick="$.operate.activeProcessInstance(\'' + row.id + '\')"><i class="fa fa-eye"></i>激活</a> ');
                             }
                             actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="getProcessDiagram(\'' + row.id + '\')"><i class="fa fa-eye"></i>详情</a>');
                             return actions.join('');
                         }
                     }]
             };
             $.table.init(options);
         });

         function getProcessDiagram(processInstanceId) {
             var preViewUrl=prefixFlow+'/myStartProcessDetail?processInstanceId='+processInstanceId;
             $.modal.openTab("详情", preViewUrl);
         }

         function fromDetailUrl(detailUrl) {
             $.modal.openTab("详情", detailUrl);

         }

     </script>
</body>
</html>